﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace BloggerImageConversion
{
    public class ImageMigrationItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private bool _selected;
        private string _original;
        private string _new;
        private int _progress;
        private string _status;

        public bool IsComplete
        {
            get
            {
                if ((!Selected) ||
                    ((Status != null && Status.StartsWith("Error")) || !String.IsNullOrWhiteSpace(New)))
                {
                    return true;
                }

                return false;
            }
        }

        public bool Selected
        {
            get
            {
                return _selected;
            }
            set
            {
                if (value != _selected)
                {
                    _selected = value;
                    NotifyPropertyChanged("Selected");
                    NotifyPropertyChanged("IsComplete");
                }

            }
        }

        public string Original
        {
            get
            {
                return _original;
            }
            set
            {
                if (value != _original)
                {
                    _original = value;
                    NotifyPropertyChanged("Original");
                }
            }
        }

        public string New
        {
            get
            {
                return _new;
            }
            set
            {
                if (value != _new)
                {
                    _new = value;
                    NotifyPropertyChanged("New");
                    NotifyPropertyChanged("IsComplete");
                }
            }
        }

        public int Progress
        {
            get
            {
                return _progress;
            }
            set
            {
                if (value != _progress)
                {
                    _progress = value;
                    NotifyPropertyChanged("Progress");
                }

            }
        }

        public string Status
        {
            get
            {
                return _status;
            }
            set
            {
                if (value != _status)
                {
                    _status = value;
                    NotifyPropertyChanged("Status");
                    NotifyPropertyChanged("IsComplete");
                }

            }
        }

        public ImageMigrationItem()
        {
            _progress = 0;
            _status = "Idle";
        }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }



    }
}
